package com.egao.orderB.service.impl;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
import com.egao.orderB.biz.OceanCustomerPlanBiz;
import com.egao.orderB.biz.OceanPreConfigurationBiz;
import com.egao.orderB.biz.OceanPreStoragePositionBiz;
import com.egao.orderB.entity.OceanCustomerPlan;
import com.egao.orderB.entity.OceanPreConfiguration;
import com.egao.orderB.entity.OceanPreStoragePosition;
import com.egao.orderB.service.OceanPreConfigurationService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

//import com.egao.orderB.mapper.OceanPreConfigurationMapper;
//import javax.transaction.Transactional;

/**
 * 预配服务实现类
 * @author : Doman
 * @date : 2021-10-20 16:59:51
 * @version ：1.0
 */
@Service
public class OceanPreConfigurationServiceImpl /*extends ServiceImpl<OceanPreConfigurationMapper, OceanPreConfiguration> */implements OceanPreConfigurationService {

	@Autowired
	private OceanPreConfigurationBiz oceanPreConfigurationBiz;
  @Autowired
  private OceanPreStoragePositionBiz oceanPreStoragePositionBiz;
  @Autowired
  private OceanCustomerPlanBiz oceanCustomerPlanBiz;

  @Override
  public JsonResult list(PageResult2<T> page, OceanPreConfiguration oceanPreConfiguration, User loginUser)  throws Exception{
    return oceanPreConfigurationBiz.list(page,oceanPreConfiguration,loginUser);
  }

  @Override
  public JsonResult list(OceanPreConfiguration oceanPreConfiguration, User loginUser) {
    return JsonResult.ok().setData(oceanPreConfigurationBiz.list(oceanPreConfiguration,loginUser));
  }

  @Override
  public JsonResult getById(OceanPreConfiguration oceanPreConfiguration) {
    return JsonResult.ok().setData(oceanPreConfigurationBiz.getById(oceanPreConfiguration));
  }

  @Transactional
  @Override
  public JsonResult save(OceanPreConfiguration oceanPreConfiguration, User loginUser) {
    if (oceanPreConfigurationBiz.save(oceanPreConfiguration, loginUser)) {
      OceanPreStoragePosition oceanPreStoragePosition = new OceanPreStoragePosition();
      oceanPreStoragePosition.setId(oceanPreConfiguration.getOceanPreStoragePositionId());
      oceanPreStoragePositionBiz.remove(oceanPreStoragePosition, loginUser);
      OceanCustomerPlan oceanCustomerPlan = new OceanCustomerPlan();
      oceanCustomerPlan.setId(oceanPreConfiguration.getOceanCustomerPlanId());
      oceanCustomerPlanBiz.remove(oceanCustomerPlan, loginUser);
      return JsonResult.ok("添加成功");
    }
    return JsonResult.error("添加失败");
  }

  @Transactional
  @Override
  public JsonResult update(OceanPreConfiguration oceanPreConfiguration, User loginUser) {
    if (oceanPreConfigurationBiz.update(oceanPreConfiguration, loginUser)) {
      return JsonResult.ok("修改成功");
    }
    return JsonResult.error("修改失败");
  }

  @Transactional
  @Override
  public JsonResult remove(OceanPreConfiguration oceanPreConfiguration, User loginUser) {
    if (oceanPreConfigurationBiz.remove(oceanPreConfiguration, loginUser)) {
      return JsonResult.ok("删除成功");
    }
    return JsonResult.error("删除失败");
  }

}
